home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 108 / MacAddict108.iso / Software / Internet & Communication / WordPress 1.5.1.dmg / wordpress / wp-admin / import-b2.php < prev    next >
Encoding:
PHP Script  |  2005-04-19  |  8.7 KB  |  247 lines

  1. <?php
  2. if (!file_exists('../wp-config.php')) die("There doesn't seem to be a wp-config.php file. Double check that you updated wp-config-sample.php with the proper database connection information and renamed it to wp-config.php.");
  3. require_once('../wp-config.php');
  4. require('upgrade-functions.php');
  5. $step = $_GET['step'];
  6. if (!$step) $step = 0;
  7. header( 'Content-Type: text/html; charset=utf-8' );
  8. ?>
  9. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  10. <html xmlns="http://www.w3.org/1999/xhtml">
  11.     <title>WordPress — b2 Conversion</title>
  12.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  13.     <style media="screen" type="text/css">
  14.     body {
  15.         font-family: Georgia, "Times New Roman", Times, serif;
  16.         margin-left: 15%;
  17.         margin-right: 15%;
  18.     }
  19.     #logo {
  20.         margin: 0;
  21.         padding: 0;
  22.         background-image: url(http://wordpress.org/images/wordpress.gif);
  23.         background-repeat: no-repeat;
  24.         height: 60px;
  25.         border-bottom: 4px solid #333;
  26.     }
  27.     #logo a {
  28.         display: block;
  29.         height: 60px;
  30.     }
  31.     #logo a span {
  32.         display: none;
  33.     }
  34.     p, li {
  35.         line-height: 140%;
  36.     }
  37.     </style>
  38. </head>
  39. <body>
  40. <h1 id="logo"><a href="http://wordpress.org"><span>WordPress</span></a></h1>
  41. <?php
  42. switch($step) {
  43.  
  44.     case 0:
  45. ?>
  46. <p>Welcome to WordPress. Since you’re upgrading from b2 everything should be relatively 
  47.   familiar to you. Here are some notes on upgrading:</p>
  48. <ul>
  49.   <li>If you’re using an older version of b2, it's probably a good idea to upgrade 
  50.     to at least .61 before making the leap to WordPress.</li>
  51.   <li>The templates are so much better, and there is so much more going on than 
  52.     before it’s probably worth it to start from scratch and work back to your 
  53.     design.</li>
  54.   <li>You need to transfer some of your settings from your old <code>b2config.php</code>
  55.     to <code>wp-config.php</code> file.</li>
  56.   <li>WordPress issues should be discussed in our <a href="http://wordpress.org/support/">support 
  57.     forums</a>.</li>
  58.   <li><strong>Back up</strong> your database before you do anything. Yes, you.</li>
  59. </ul>
  60. <p>Have you looked at the <a href="../readme.html">readme</a>? If 
  61.   you’re all ready, <a href="import-b2.php?step=1">let’s go</a>!</p>
  62. <?php
  63.     break;
  64.     
  65.     case 1:
  66. ?>
  67. <h1>Step 1</h1>
  68. <p>Okay first we’re going to set up the links database. This will allow you to host your own blogroll, complete with Weblogs.com updates.</p>
  69. <?php
  70.  
  71. $got_links = false;
  72. $got_cats = false;
  73. $got_row = false;
  74. ?>
  75. <p>Installing WP-Links.</p>
  76. <p>Checking for tables...</p>
  77. <?php
  78. $result = mysql_list_tables(DB_NAME);
  79. if (!$result) {
  80.     print "DB Error, could not list tables\n";
  81.     print 'MySQL Error: ' . mysql_error();
  82.     exit;
  83. }
  84.  
  85. while ($row = mysql_fetch_row($result)) {
  86.     if ($row[0] == $wpdb->links)
  87.         $got_links = true;
  88.     if ($row[0] == $wpdb->linkcategories)
  89.         $got_cats = true;
  90.     //print "Table: $row[0]<br />\n";
  91. }
  92. if (!$got_cats) {
  93.     echo "<p>Can't find table '$wpdb->linkcategories', gonna create it...</p>\n";
  94.     $sql = "CREATE TABLE $wpdb->linkcategories ( " .
  95.            " cat_id int(11) NOT NULL auto_increment, " .
  96.            " cat_name tinytext NOT NULL, ".
  97.            " auto_toggle enum ('Y','N') NOT NULL default 'N', ".
  98.            " PRIMARY KEY (cat_id) ".
  99.            ") ";
  100.     $result = mysql_query($sql) or print ("Can't create the table '$wpdb->linkcategories' in the database.<br />" . $sql . "<br />" . mysql_error());
  101.     if ($result != false) {
  102.         echo "<p>Table '$wpdb->linkcategories' created OK</p>\n";
  103.         $got_cats = true;
  104.     }
  105. } else {
  106.     echo "<p>Found table '$wpdb->linkcategories', don't need to create it...</p>\n";
  107.         $got_cats = true;
  108. }
  109. if (!$got_links) {
  110.     echo "<p>Can't find '$wpdb->links', gonna create it...</p>\n";
  111.     $sql = "CREATE TABLE $wpdb->links ( " .
  112.            " link_id int(11) NOT NULL auto_increment,           " .
  113.            " link_url varchar(255) NOT NULL default '',         " .
  114.            " link_name varchar(255) NOT NULL default '',        " .
  115.            " link_image varchar(255) NOT NULL default '',       " .
  116.            " link_target varchar(25) NOT NULL default '',       " .
  117.            " link_category int(11) NOT NULL default 0,          " .
  118.            " link_description varchar(255) NOT NULL default '', " .
  119.            " link_visible enum ('Y','N') NOT NULL default 'Y',  " .
  120.            " link_owner int NOT NULL DEFAULT '1',               " .
  121.            " link_rating int NOT NULL DEFAULT '0',              " .
  122.            " link_updated DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', " .
  123.            " link_rel varchar(255) NOT NULL default '',         " .
  124.            " link_notes MEDIUMTEXT NOT NULL default '',         " .
  125.            " PRIMARY KEY (link_id)                              " .
  126.            ") ";
  127.     $result = mysql_query($sql) or print ("Can't create the table '$wpdb->links' in the database.<br />" . $sql . "<br />" . mysql_error());
  128.     $links = mysql_query("INSERT INTO $wpdb->links VALUES ('', 'http://wordpress.org/', 'WordPress', '', '', 1, '', 'Y', 1, 0, '0000-00-00 00:00:00', '');");
  129.     $links = mysql_query("INSERT INTO $wpdb->links VALUES ('', 'http://photomatt.net/', 'Matt', '', '', 1, '', 'Y', 1, 0, '0000-00-00 00:00:00', '');");
  130.     $links = mysql_query("INSERT INTO $wpdb->links VALUES ('', 'http://zed1.com/b2/', 'Mike', '', '', 1, '', 'Y', 1, 0, '0000-00-00 00:00:00', '');");
  131.  
  132.     if ($result != false) {
  133.         echo "<p>Table '$wpdb->links' created OK</p>\n";
  134.         $got_links = true;
  135.     }
  136. } else {
  137.     echo "<p>Found table '$wpdb->links', don't need to create it...</p>\n";
  138.     echo "<p>... may need to update it though. Looking for column link_updated...</p>\n";
  139.     $query = "SELECT link_updated FROM $wpdb->links LIMIT 1";
  140.     $q = @mysql_query($query);
  141.     if ($q != false) {
  142.         if ($row = mysql_fetch_object($q)) {
  143.             echo "<p>You have  column link_updated. Good!</p>\n";
  144.         }
  145.     } else {
  146.         $query = "ALTER TABLE $wpdb->links ADD COLUMN link_updated DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'";
  147.         $q = mysql_query($query) or mysql_doh("Doh, couldn't add column.", $query, mysql_error());
  148.         echo "<p>Added column link_updated...</p>\n";
  149.     }
  150.     echo "<p>Looking for column link_rel...</p>\n";
  151.     $query = "SELECT link_rel FROM $wpdb->links LIMIT 1";
  152.     $q = @mysql_query($query);
  153.     if ($q != false) {
  154.         if ($row = mysql_fetch_object($q)) {
  155.             echo "<p>You have column link_rel. Good!</p>\n";
  156.         }
  157.     } else {
  158.         $query = "ALTER TABLE $wpdb->links ADD COLUMN link_rel varchar(255) NOT NULL DEFAULT '' ";
  159.         $q = mysql_query($query) or mysql_doh("Doh, couldn't add column.", $query, mysql_error());
  160.         echo "<p>Added column link_rel...</p>\n";
  161.     }
  162.     $got_links = true;
  163. }
  164.  
  165. if ($got_links && $got_cats) {
  166.     echo "<p>Looking for category 1...</p>\n";
  167.     $sql = "SELECT * FROM $wpdb->linkcategories WHERE cat_id=1 ";
  168.     $result = mysql_query($sql) or print ("Can't query '$wpdb->linkcategories'.<br />" . $sql . "<br />" . mysql_error());
  169.     if ($result != false) {
  170.         if ($row = mysql_fetch_object($result)) {
  171.             echo "<p>You have at least 1 category. Good!</p>\n";
  172.             $got_row = true;
  173.         } else {
  174.             echo "<p>Gonna insert category 1...</p>\n";
  175.             $sql = "INSERT INTO $wpdb->linkcategories (cat_id, cat_name) VALUES (1, 'General')";
  176.             $result = mysql_query($sql) or print ("Can't query insert category.<br />" . $sql . "<br />" . mysql_error());
  177.             if ($result != false) {
  178.                 echo "<p>Inserted category Ok</p>\n";
  179.                 $got_row = true;
  180.             }
  181.         }
  182.     }
  183. }
  184.  
  185. if ($got_row) {
  186.     echo "<p>All done!</p>\n";
  187. }
  188. ?>
  189. <p>Did you defeat the boss monster at the end? Good, then you’re ready for 
  190.   <a href="import-b2.php?step=2">Step 2</a>.</p>
  191. <?php
  192.     break;
  193.     case 2:
  194. ?>
  195. <h1>Step 2</h1>
  196. <p>First we’re going to add excerpt, post, and password functionality...</p>
  197.  
  198. <?php
  199.  
  200. $query = "ALTER TABLE $wpdb->posts ADD COLUMN post_excerpt text NOT NULL;";
  201. $q = $wpdb->query($query);
  202. // 0.71 mods
  203. $query = "ALTER TABLE $wpdb->posts ADD post_status ENUM('publish','draft','private') NOT NULL,
  204. ADD comment_status ENUM('open','closed') NOT NULL,
  205. ADD ping_status ENUM('open','closed') NOT NULL,
  206. ADD post_password varchar(20) NOT NULL;";
  207. $q = $wpdb->query($query);
  208. ?>
  209.  
  210. <p>That went well! Now let's clean up the b2 database structure a bit...</p>
  211.  
  212. <?php
  213. $query = "ALTER TABLE $wpdb->posts DROP INDEX ID";
  214.  
  215. $q = $wpdb->query($query);
  216.  
  217. ?>
  218.  
  219. <p>One down, two to go...</p>
  220.  
  221.  
  222. <p>So far so good.</p>
  223. <?php
  224.  
  225. $query="ALTER TABLE $wpdb->posts DROP post_karma";
  226. $q = $wpdb->query($query);
  227. flush();
  228. ?>
  229.  
  230. <p>Almost there...</p>
  231.  
  232. <?php
  233.  
  234. $query = "ALTER TABLE $wpdb->users DROP INDEX ID";
  235.  
  236. $q = $wpdb->query($query);
  237. upgrade_all();
  238. ?>
  239.  
  240. <p>Welcome to the family. <a href="../">Have fun</a>!</p>
  241.   <?php
  242.     break;
  243. }
  244. ?>
  245.  
  246. </body>
  247. </html>